stringsIntro
Strings Intro Mar10 PanosP Revised

Introduction to Strings 

Strings in awk are any sequences of characters of any kind: letters,
digits, symbols, control characters, blanks etc. There are string
literals and variables. String literals are character sequences 
enclosed in double quotes, e.g. "panos", "abc123", "this is line
one\nthis is line 2" etc. String variables are variables that contain
strings. Even number variables may be handled as strings, it's just
a matter of concept. Let's look some examples:

  x = "abc"

Defines the variable named x having the string "abc" as a value.
That means that if we print x, the "abc" character sequence will
be printed (without the quotes, of course).

  x = 123

Defines the variable x having the number 123 as a value. But we can
use the x variable as a string, e.g.

  y = "panos" x "papadopoulos"

will put the string "panos123papadopoulos" in variable y. That is
a consequence of the string concatenation in awk which is achieved
by just puting the strings to concatenate one after the other,
without any kind of extra operator (very easy). So, if, by mistake,
we had writen:

  y = "panos" + x + "papadopoulos"

then y would have taken the number value of 123, as "panos" will
be "added" with the (number) 123 and the result will be added with
the string "papadopoulos" taken as a number. Both "panos" and
"papadopoulos" will give the value of zero if taken as numbers.
Every string not begining with digits (with the exception of white
characters) will have the numeric value of zero if taken as a number.
So:

+  "panos123" have the number value of zero, 
+ "123panos" have the number value of 123, 
+ "123.23panos" have the number value of 123.23
+ "   123panos" (with three spaces in front of 1) will have the number value of 123.

 function StringsDemo(   x, y1, y2, z1, z2, z3, z4) {
 	x = "abc"
 	x = "123"
 	y1= "panos" x "papadoupoulous"
 	y2= "panos" + x + "papadopoulos"
 	z1= "panos123" + 1
 	z2= "123paons" + 1
 	z3= "123.23panos" + 1
 	z4= "   123panos" + 1
 	print("x=["x"] y1=["y1"] z1=["z1"] z2=["z2"] z3=["z3"] z4=["z4"]")
 }   

There is a small suite of library functions for handling and
manipulating strings in awk. These functions are not so many as in
other languages, e.g. PHP, or Java, but you can easily construct
your own functions using these primitive functions.

